package com.example.helloworld;

import jdk.nashorn.api.scripting.URLReader;

import java.io.*;

public class FileStreamTest {
    public static void main(String[] args) throws IOException {
        File f = new File("test.txt");
        FileOutputStream fos = new FileOutputStream(f);
        OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
        osw.append("中文输入");
        osw.append("\r\n");
        osw.append("English");
        osw.close();
        fos.close();
        FileInputStream fis = new FileInputStream(f);
        InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
        StringBuffer sb = new StringBuffer();

        while (isr.ready()) {
            sb.append((char) isr.read());
        }
        System.out.println(sb.toString());
        isr.close();
        fis.close();
    }
}
